<template>
	<view class="category">
		<view class="brandBox" v-if="brandList[0].length>0">
			<view class="u-p-l-30 u-p-r-30 u-p-t-14 u-p-b-14">
				<view class="brandContent">
					<swiper class="swiper" @change="brandChange" :current="brandCurrent" style="height: 280rpx;">
						<swiper-item style="border-radius: 10rpx;" v-for="(item, index) in brandList" :key="index">
							<u-grid :col="4"  hover-class="hover-class" :border="false">
								<u-grid-item class="u-p-20" v-for="(item2, index) in item" :index="index" :key="index" @click="clickHandle(item2, index)">
									<u-image :src="item2.picture" style="width: 50rpx;height: 50rpx;"></u-image>
									<text class="grid-text u-line-1 u-font-26">{{item2.name}}</text>
								</u-grid-item>
							</u-grid>
						</swiper-item>
					</swiper>
				</view>
			</view>
		</view>
		<view class="u-m-t-10"  v-if="secCateData[0].length>0">
			<swiper class="swiper" @change="cateChange" :current="cateCurrent" style="height: 250rpx;">
				<swiper-item style="border-radius: 10rpx;" v-for="(item, index) in secCateData" :key="index">
					<u-grid :col="4" hover-class="hover-class" :border="false">
						<u-grid-item class="u-p-20" v-for="(item2, index) in item" :index="index" :key="index" @click="clickHandle(item2, index)">
							<u-image :src="item2.picture" style="width: 50rpx;height: 50rpx;"></u-image>
							<text class="grid-text u-line-1 u-font-26">{{item2.name}}</text>
						</u-grid-item>
					</u-grid>
				</swiper-item>
			</swiper>
			
			<view class="indicator-dots">
				<view class="indicator-dots-item" v-for="(item, index) in secCateData" :key="index"
					:class="[cateCurrent==index ? 'indicator-dots-active' : '' ]">
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				brandCurrent:0,
				cateCurrent:0
			}
		},
		props: {
			brandList: {
				type: Array,
				default: () => {
					return []
				}
			},
			secCateData: {
				type: Array,
				default: () => {
					return []
				}
			},
			brandIndex: {
				type: [Number, String],
				default: 0
			},
			secCateIndex: {
				type: [Number, String],
				default: 0
			}
		},
		watch: {
			brandIndex(n) {
				this.brandCurrent = n;
			},
			secCateIndex(n) {
				this.cateCurrent = n;
			}
		},
		methods:{
			brandChange(e) {
				this.$emit('brandCurChange',e.detail.current);
				this.brandCurrent = e.detail.current;
			},
			cateChange(e) {
				this.$emit('cateCurChange',e.detail.current);
				this.cateCurrent = e.detail.current;
			},
			clickHandle(item,index){
				uni.navigateTo({
					url: `/pages/search/index?id=${item.id}&name=${item.name}`
				})
			}
		}
	}
</script>

<style scoped>
	.brandBox {
		width: 100%;
		height: 160rpx;
		background: linear-gradient(to right, #FF6801, #FF9832);
		margin-bottom: 150rpx;
	}

	.brandContent {
		width: 100%;
		background-color: #ffffff;
		border-radius: 10rpx;
		box-shadow: 1px 1px 4px #f2f2f2;
	}
	.indicator-dots {
		display: flex;
		justify-content: center;
		align-items: center;
		margin: 20rpx 0;
	}
	
	.indicator-dots-item {
		background-color: #ADADAD;
		height: 12rpx;
		width: 12rpx;
		border-radius: 20rpx;
		margin: 0 6rpx;
	}
	
	.indicator-dots-active {
		background-color: #FF6600;
	}
</style>
